package com.qifan.alb2b.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import com.cqcis.base.orm.jdbc.JdbcUtil;
import com.qifan.alb2b.domain.CompanyInfoDomain;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.Page;

/**
 * 酒店CURD的Dao
 * @author lj
 *
 */
@Repository
public class CompanyInfoDao extends BaseDao{
	private static final Log logger=LogFactory.getLog(CompanyInfoDao.class);
//	private int update;
	
	/**
	 * 根据条件分页查询酒店信息
	 * @param dgm 分页参数
	 * @param uqp 客户查询参数
	 * @return Page对象（分页信息&分页数据）
	 */
	public Page query(DataGridModel dgm,CompanyInfoDomain uqp){
		logger.debug("查询客户");
		/* 构建sql */
		StringBuilder sql=new StringBuilder();
		List<Object> params=new ArrayList<Object>();
		sql.append("select * from companyinfo where 1=1");
//		if(uqp.getHotelName()!=null&&!"".equals(uqp.getHotelName())){
//			sql.append(" and hotelName like ?");
//			params.add("%"+uqp.getHotelName()+"%");
//		}
//		if(uqp.getHotelLevel()>0){
//			sql.append(" and hotelLevel=?");
//			params.add(uqp.getHotelLevel());
//		}
//		if(uqp.getHotelLocation()!=null){
//			sql.append(" and hotelLocation>=?");
//			params.add(uqp.getHotelLocation());
//		}
//		if(uqp.getHotelAddress()!=null){
//			sql.append(" and hotelAddr like ?");
//			params.add("%"+uqp.getHotelName()+"%");
//			
//		}
//		if(uqp.getHotelCity()!=null){
//			sql.append(" and cityId=?");
//			params.add(uqp.getHotelCity());
//		}
//		return super.queryMapByPage(sql.toString(), dgm.getRows(), dgm.getPage(),params);
		return super.queryObjByPage(sql.toString(), dgm.getRows(), dgm.getPage(), params, CompanyInfoDomain.class);
	}
	
	public CompanyInfoDomain getCompanyById(String id){
		String sql="select * from companyinfo where compId=?";
		List<CompanyInfoDomain> list= JdbcUtil.queryForList(this, CompanyInfoDomain.class, sql, id);
		if(list.size()>0)
			return list.get(0);
		return null;
	}
	public CompanyInfoDomain getCompanyByName(String name){
		String sql="select * from companyinfo where compName=?";
		List<CompanyInfoDomain> list= JdbcUtil.queryForList(this, CompanyInfoDomain.class, sql, name);
		if(list.size()>0)
			return list.get(0);
		return null;
	}
	
	/**
	 * 增加一个客户信息
	 * @param CompanyInfoDomain
	 */
	public void add(CompanyInfoDomain companyInfoDomain){
		super.addObj(companyInfoDomain);
	}
	
	public void update(CompanyInfoDomain companyInfoDomain){
		super.updateObj(companyInfoDomain, "compId");
	}
	
	/**
	 * 批量删除
	 * @param ids
	 */
	public void delete(String[] ids){
		StringBuilder delSql=new StringBuilder();
		delSql.append("delete from companyinfo where compId in(");
		for(int i=0;i<ids.length-1;i++){
			delSql.append("?,");
		}
		delSql.append("?)");
		this.getJdbcTemplate().update(delSql.toString(), ids);
	}
	
}
